package wash

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/assets-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/assets-api/internal/types"
	"gitee.com/liuxuezhan/ar-platform/assets-api/pkg/xerrors"
	"gitee.com/liuxuezhan/ar-platform/base-common/headInfo"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/client/userwash"
	"github.com/jinzhu/copier"
	"github.com/zeromicro/go-zero/core/logx"
)

type UserWashBetInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 洗码页面--洗码信息
func NewUserWashBetInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserWashBetInfoLogic {
	return &UserWashBetInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserWashBetInfoLogic) UserWashBetInfo(req *types.UserWashBetInfoRequest) (resp *types.UserWashBetInfoResponse, err error) {
	resp = &types.UserWashBetInfoResponse{}
	userId := headInfo.GetTokenUid(l.ctx)
	if userId == 0 {
		return nil, xerrors.UserTokenInvalid
	}

	userWashBet, err := l.svcCtx.AssetsRpc.UserWash.UserWashBet(l.ctx, &userwash.UserWashBetRequest{
		UserId:   userId,
		TypeName: req.TypeName,
	})
	if err != nil {
		return nil, err
	}
	copier.Copy(&resp, &userWashBet)
	return
}
